package com.example.ncov_management_system.controller;

import com.example.ncov_management_system.entity.Clbum;
import com.example.ncov_management_system.service.ClbumService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/clbum")
public class ClbumController {
    @Autowired
    private ClbumService clbumService;

    @GetMapping("/list")
    public String list(Model model) {
        model.addAttribute("clbums", clbumService.list());
        return "clbum_list";
    }

    @PostMapping("/add")
    public String add(String name) {
        clbumService.add(name);
        return "redirect:/clbum/list";
    }

    @GetMapping("/edit/{id}")
    public String info(@PathVariable long id, Model model) {
        model.addAttribute("clbum", clbumService.findById(id));
        return "clbum_edit";
    }

    @PostMapping("/edit")
    public String edit(Clbum clbum) {
        clbumService.save(clbum);
        return "redirect:/clbum/list";
    }
    @GetMapping("/delete/{id}")
    public String delete(@PathVariable long id) {
        clbumService.deleteById(id);
        return "redirect:/clbum/list";
    }
}
